package com.filldream.fastboot.common.util.entity.wxpay;

import com.filldream.fastboot.common.util.PayUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Map;
import java.util.TreeMap;

/**
 * @author RickSun
 * @Description 微信支付-用户到商户
 **/
@Data
public class WxC2BSTO extends WxPaySTO{

    @ApiModelProperty(value = "支付者的openId")
    private String openid;

    @ApiModelProperty(value = "小程序的AppId")
    private String appid;

    @ApiModelProperty(value = "小程序的APPID")
    private String mch_id;

    @ApiModelProperty("支付给商户-订单号，自给自足")
    private String out_trade_no;

    @ApiModelProperty("支付给商户-标价金额，自给自足")
    private String total_fee;

    @ApiModelProperty("支付给商户-回调地址，自给自足")
    private String notify_url;

    @ApiModelProperty("支付给商户-支付类型，SAPI--JSAPI支付(或小程序支付)、NATIVE--Native支付、APP--app支付，MWEB--H5支付")
    private String trade_type;

    @ApiModelProperty("商品描述")
    private String body;

    public Map<String,String> reSign(Map<String,String> params,String signKey){
        //再次签名
        Map<String, String> returnMap = new TreeMap<>();
        //返回的预付单信息
        returnMap.put("appId",this.getAppid());
        returnMap.put("nonceStr", params.get("nonce_str"));
        String prepay_id = params.get("prepay_id");
        returnMap.put("package", "prepay_id=" + prepay_id);
        returnMap.put("signType","MD5");
        //这边要将返回的时间戳转化成字符串，不然小程序端调用wx.requestPayment方法会报签名错误
        returnMap.put("timeStamp", params.get("timeStamp"));
        //加密
        returnMap.put("paySign",PayUtil.sign(PayUtil.build(returnMap, "key", signKey)));
        return returnMap;
    }

}